import Transaction from "https://cdn.jsdelivr.net/npm/@konghayao/promise-transaction/dist/promiseTransaction.browser.js";
import addAnime from "../plugins/Anime.js";
import FlowerTale from "./components/FlowerTale.js";
import throttle from "https://cdn.jsdelivr.net/npm/lodash-es/throttle.js";

export default new Transaction([
    [
        "load resource",
        () =>
            window.assetsLoader({
                Flower: {
                    0: [
                        "./image/Flower/Flower-1-0.webp",
                        "./image/Flower/Flower-1-1.webp",
                    ],
                    1: [
                        "./image/Flower/Flower-2-0.webp",
                        "./image/Flower/Flower-2-1.webp",
                        "./image/Flower/Flower-2-2.webp",
                        "./image/Flower/Flower-2-3.webp",
                        "./image/Flower/Flower-2-4.webp",
                        "./image/Flower/Flower-2-5.webp",
                    ],
                    2: [
                        "./image/Flower/Flower-3-0.webp",
                        "./image/Flower/Flower-3-1.webp",
                    ],
                    3: [
                        "./image/Flower/Flower-4-0.webp",
                        "./image/Flower/Flower-4-1.webp",
                    ],
                    4: [
                        "./image/Flower/Flower-5-0.webp",
                        "./image/Flower/Flower-5-1.webp",
                        "./image/Flower/Flower-5-2.webp",
                        "./image/Flower/Flower-5-3.webp",
                        "./image/Flower/Flower-5-4.webp",
                        "./image/Flower/Flower-5-5.webp",
                    ],
                    5: [
                        "./image/Flower/Flower-6-0.webp",
                        "./image/Flower/Flower-6-1.webp",
                    ],
                    6: ["./image/Flower/Flower-7-0.webp"],
                },
            }),
    ],
    [
        "createFlower",
        () => {
            var container = new PIXI.Container();
            let sprite = new PIXI.AnimatedSprite(Resources["Flower"]);
            const config = {
                animationSpeed: 0.01,
                interactive: true,
                height: 320 * px,
                width: 320 * px,
                x: app.config.width / 2,
                y: 750 * px,
                alpha: 0,

                anchor: { x: 0.5, y: 0.5 },
            };
            Object.assign(sprite, config);
            addAnime(sprite);
            sprite.changeStates("0");
            sprite.HitObject = new PIXI.Rectangle(
                config.x,
                config.y,
                config.width / 2,
                config.height / 2
            );

            container.addChild(sprite);
            container.zIndex = -99;
            app.stage.Flower = sprite;
            app.stage.addChild(container);
        },
    ],
    [
        "Flower Event",
        () => {
            app.stage.Flower.on(
                "pointerdown",
                throttle(() => {
                    mui.toast(
                        FlowerTale[
                            Math.floor(Math.random() * FlowerTale.length)
                        ]
                    );
                }, 3000)
            );
        },
    ],
]);
